// -*- c -*-
#include "../Packets.h"
#include "PolyClass/horner.c"
#include <stdio.h>
#include <stdint.h>
#ifdef DEBUG
#define NEW_PRINTF_SEMANTICS
#include "printf.h"
#endif 

configuration CogentHouseC {}
implementation
{
  components CogentHouseP, ActiveMessageC, MainC, LedsC, ActiveMessageC as Radio;
#ifdef DEBUG
  components PrintfC;
  components SerialStartC;
#endif
	
  //import timers
  components new TimerMilliC() as SenseTimer;
  components new TimerMilliC() as AckTimeoutTimer;
  components new TimerMilliC() as BlinkTimer;
  components new TimerMilliC() as WarmUpTimer;   
  components new AMSenderC(AM_STATEMSG) as StateSender;
  components new AMSenderC(AM_STATEMSG) as StateForwarder;
  components new AMSenderC(AM_ACKMSG) as AckForwarder;
  components new AMReceiverC(AM_ACKMSG) as AckReceiver;
  components new AMReceiverC(AM_STATEMSG) as StateReceiver;

  CogentHouseP.Boot -> MainC.Boot;
  CogentHouseP.StateSender -> StateSender;  
  CogentHouseP.StateForwarder -> StateForwarder;
  CogentHouseP.AckForwarder -> AckForwarder;
  CogentHouseP.AckReceiver -> AckReceiver;
  CogentHouseP.StateReceiver -> StateReceiver;
  CogentHouseP.SenseTimer -> SenseTimer;
  CogentHouseP.AckTimeoutTimer -> AckTimeoutTimer;
  CogentHouseP.BlinkTimer -> BlinkTimer;
  CogentHouseP.Leds -> LedsC;
  CogentHouseP.RadioControl -> ActiveMessageC;

  //sensing interfaces
  components new SensirionSht11C();
  components new HamamatsuS1087ParC() as PAR;
  components new HamamatsuS10871TsrC() as TSR;
  components new VoltageC() as Volt;



  components new Temp_ADC1C() as Temp_ADC1;
  components new Temp_ADC2C() as Temp_ADC2;
  components new Temp_ADC3C() as Temp_ADC3;
  components new Flow_ADC3C() as Flow_ADC3;
  components new Flow_ADC7C() as Flow_ADC7;
  components new SolarC() as Solar;
  components new Solar_ADC3C() as Solar_ADC3;
  components new BlackBulbC() as BlackBulb;
  components new CarbonDioxideC() as CarbonDioxide;
  components BatterySensingM;
  components HplMsp430InterruptP as GIOInterrupt;
  components HplMsp430GeneralIOC as GIO;

  //import sensing modules
  components ThermalSensingM;
  components LightSensingM;
  components CarM;

  //sensor readings
  ThermalSensingM.GetTemp -> SensirionSht11C.Temperature;
  ThermalSensingM.GetHum ->SensirionSht11C.Humidity;

  LightSensingM.GetPAR -> PAR;
  LightSensingM.GetTSR -> TSR;
  BatterySensingM.GetVoltage -> Volt;
  CarM.GetTempADC1 -> Temp_ADC1;
  CarM.GetTempADC2 -> Temp_ADC2;
  CarM.GetTempADC3 -> Temp_ADC3;
  CarM.GetFlowADC3 -> Flow_ADC3;
  CarM.GetFlowADC7 -> Flow_ADC7;
  CarM.GetSolar -> Solar;
  CarM.GetSolar_ADC3 -> Solar_ADC3;
  CarM.GetBlackBulb -> BlackBulb;
  CarM.GetCO2 -> CarbonDioxide;
  CarM.CO2On -> GIO.Port23; //set to gio2
  CarM.WarmUpTimer -> WarmUpTimer;
  CarM.MotionInput -> GIO.Port26;
  CarM.MotionInterrupt -> GIOInterrupt.Port26; //set to read from gio3

  //link modules to main file
  CogentHouseP.ReadTemp->ThermalSensingM.ReadTemp;
  CogentHouseP.ReadHum->ThermalSensingM.ReadHum;
  CogentHouseP.ReadPAR->LightSensingM.ReadPAR;
  CogentHouseP.ReadTSR->LightSensingM.ReadTSR;
  CogentHouseP.ReadVolt->BatterySensingM.ReadBattery;

  CogentHouseP.ReadCO2->CarM.ReadCO2;
  CogentHouseP.ReadTempADC1->CarM.ReadTempADC1;
  CogentHouseP.ReadTempADC2->CarM.ReadTempADC2;
  CogentHouseP.ReadTempADC3->CarM.ReadTempADC3;
  CogentHouseP.ReadFlowADC3->CarM.ReadFlowADC3;
  CogentHouseP.ReadFlowADC7->CarM.ReadFlowADC7;
  CogentHouseP.ReadSolar->CarM.ReadSolar;
  CogentHouseP.ReadSolar_ADC3->CarM.ReadSolar_ADC3;
  CogentHouseP.ReadBlackBulb->CarM.ReadBlackBulb;
  CogentHouseP.ReadMotion->CarM.ReadMotion;
  CogentHouseP.MotionControl -> CarM.MotionControl;

  components HilTimerMilliC;	
  CogentHouseP.LocalTime -> HilTimerMilliC;

  //Need to define right size
  components new AccessibleBitVectorC(RS_SIZE) as Configured;
  CogentHouseP.Configured -> Configured.AccessibleBitVector;

  //expectReadDone
  components new BitVectorC(RS_SIZE) as ExpectReadDone;
  CogentHouseP.ExpectReadDone -> ExpectReadDone.BitVector;


  //PackState
  components new PackStateC(SC_SIZE) as PackState;
  components new AccessibleBitVectorC(SC_SIZE) as ABV;

  PackState.Mask -> ABV;
  CogentHouseP.PackState -> PackState;
}
